﻿using System;
using System.Xml.Linq;
using VisualWip.Core;
using VisualWip.Core.Interfaces;

namespace VisualWip.Util
{
    public class FilePersistanceProvider : IPersistanceProvider
    {
        private readonly PersistanceProvider _persistanceProvider;

        public FilePersistanceProvider(PersistanceProvider persistanceProvider)
        {
            _persistanceProvider = persistanceProvider;
        }

        #region IPersistanceProvider Members

        public void Persist(Application application, SettingsPath settingsPath)
        {
            XDocument document = _persistanceProvider.GetPersistenceDocument(application);
            document.Save(settingsPath.Path);
        }


        public void Load(Application application, SettingsPath settingsPath)
        {
             XDocument document = XDocument.Load(settingsPath.Path);
            _persistanceProvider.LoadPercistanceDocument(document, application);
        }

        #endregion

    }
}